package com.ycy.smartcourseselection.controller;

import com.ycy.smartcourseselection.common.PageResVO;
import com.ycy.smartcourseselection.common.ResData;
import com.ycy.smartcourseselection.dto.student.FindAllStuDTO;
import com.ycy.smartcourseselection.dto.student.FindPageStuDTO;
import com.ycy.smartcourseselection.dto.student.ForgetStuPwdDTO;
import com.ycy.smartcourseselection.dto.student.StudentDTO;
import com.ycy.smartcourseselection.dto.teacher.FindAllTchDTO;
import com.ycy.smartcourseselection.service.StudentService;
import com.ycy.smartcourseselection.vo.student.StudentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "学生管理")
@RestController
@RequestMapping("/student")
public class StudentController {
    @Resource
    private StudentService studentService;

    //分页查学生
    @PostMapping("/findPage")
    @ApiOperation(value="学生 -- 分页查",notes = "otherParams中的条件可选,支持联查")
    public ResData<PageResVO<StudentVO>> findPageStu(@RequestBody FindPageStuDTO findPageStuDTO) {
        return studentService.findPageStu(findPageStuDTO);
    }
    //增加或修改学生信息
    @PostMapping("/save")
    @ApiOperation(value="学生 -- 添加或修改",notes = "不带id为添加,否则为修改")
    public ResData<Boolean> saveStu(@RequestBody StudentDTO studentDTO) {
        return studentService.saveStu(studentDTO);
    }
    //假删除学生信息
    @DeleteMapping("/deleteByIds")
    @ApiOperation(value="学生 -- 批量删除(假)",notes = "传删除课程的id数组")
    public ResData<Boolean> falseDeleteStuByIds(@RequestBody List<String> idList) {
        return studentService.falseDeleteStuByIds(idList);
    }
    //根据学号查询个人信息
    @GetMapping("/getInfo")
    @ApiOperation(value="学生 -- 根据学号查询个人信息")
    public ResData<StudentVO> getInfo(String studentId) {
        return studentService.getInfo(studentId);
    }
    //重设密码
    @PostMapping("/modifyPwd")
    @ApiOperation(value="学生 -- 重设密码")
    public ResData<Boolean> modifyPwd(ForgetStuPwdDTO forgetStuPwdDTO) {
        return studentService.modifyPwd(forgetStuPwdDTO);
    }
    //表格导入
    @PostMapping("/fileImport")
    @ApiOperation("学生 -- 表格导入")
    public ResData<Boolean> stuInfoImport(@RequestPart @ApiParam(value = "表格对象") MultipartFile file){
        return studentService.stuInfoImport(file);
    }
    @GetMapping("/fileExport")
    @ApiOperation("学生 -- 表格导出")
    public void stuInfoExport(HttpServletResponse response, FindAllStuDTO findAllStuDTO) {
        studentService.stuInfoExport(response, findAllStuDTO);
    }
}
